package io.renren.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import io.renren.common.service.impl.CrudServiceImpl;
import io.renren.dao.SysparamDao;
import io.renren.dto.SysparamDTO;
import io.renren.entity.SysparamEntity;
import io.renren.service.SysparamService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * ${comments}
 *
 * @author Sen 524227263@qq.com
 * @since 1.0.0 2024-05-28
 */
@Service
public class SysparamServiceImpl extends CrudServiceImpl<SysparamDao, SysparamEntity, SysparamDTO> implements SysparamService {

    @Override
    public QueryWrapper<SysparamEntity> getWrapper(Map<String, Object> params) {
        String id = (String) params.get("id");

        QueryWrapper<SysparamEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StrUtil.isNotBlank(id), "id", id);

        return wrapper;
    }


    @Override
    public String getAutoNoCheckFlag() {
        QueryWrapper<SysparamEntity> wrapper = new QueryWrapper<>();
        wrapper.select("Value");
        wrapper.eq("Name", "AbroadCheck");
        List<SysparamEntity> list = baseDao.selectList(wrapper);
        if (list.size() > 0) {
            SysparamEntity sEntity = list.get(0);
            return sEntity.getValue();
        }
        return "";
    }

    @Override
    public String findCompNameByName(String compName) {
        QueryWrapper<SysparamEntity> wrapper = new QueryWrapper<>();
        wrapper.select("Value");
        wrapper.eq("Name", compName);
        List<SysparamEntity> list = baseDao.selectList(wrapper);
        if (list.size() > 0) {
            SysparamEntity sEntity = list.get(0);
            return sEntity.getValue();
        }
        return "";
    }
}